import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 侧边栏折叠状态
  const sidebarCollapsed = ref(false)
  
  // 全局加载状态
  const globalLoading = ref(false)
  
  // 主题设置
  const theme = ref(localStorage.getItem('graduation_check_theme') || 'light')
  
  // 当前页面标题
  const pageTitle = ref('毕业论文智能查重系统')
  
  // 面包屑导航
  const breadcrumbs = ref([])
  
  // 切换侧边栏
  function toggleSidebar() {
    sidebarCollapsed.value = !sidebarCollapsed.value
  }
  
  // 设置全局加载状态
  function setGlobalLoading(loading) {
    globalLoading.value = loading
  }
  
  // 设置主题
  function setTheme(newTheme) {
    theme.value = newTheme
    localStorage.setItem('graduation_check_theme', newTheme)
    document.documentElement.setAttribute('data-theme', newTheme)
  }
  
  // 设置页面标题
  function setPageTitle(title) {
    pageTitle.value = title
    document.title = `${title} - 毕业论文智能查重系统`
  }
  
  // 设置面包屑导航
  function setBreadcrumbs(items) {
    breadcrumbs.value = items
  }
  
  return {
    // 状态
    sidebarCollapsed,
    globalLoading,
    theme,
    pageTitle,
    breadcrumbs,
    
    // 方法
    toggleSidebar,
    setGlobalLoading,
    setTheme,
    setPageTitle,
    setBreadcrumbs
  }
})